package com.zsy.yygh.hospital.controller;

import com.zsy.yygh.common.result.Result;
import com.zsy.yygh.hospital.service.HospitalService;
import com.zsy.yygh.model.hospital.Hospital;
import com.zsy.yygh.vo.hospital.HospitalQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zhangshuaiyin
 * @date 2021-07-20 10:08
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    private final HospitalService hospitalService;

    public HospitalController(HospitalService hospitalService) {
        this.hospitalService = hospitalService;
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "limit", value = "每页记录数", required = true),
            @ApiImplicitParam(name = "hospitalQueryVo", value = "查询对象", required = false)
    })
    public Result<Page<Hospital>> index(@PathVariable Integer page,
                                        @PathVariable Integer limit,
                                        HospitalQueryVO hospitalQueryVo) {
        return Result.ok(hospitalService.selectPage(page, limit, hospitalQueryVo));
    }

    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result<?> lock(@ApiParam(name = "id", value = "医院id", required = true)
                          @PathVariable("id") String id,
                          @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
                          @PathVariable("status") Integer status) {
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    @ApiOperation(value = "获取医院详情")
    @GetMapping("show/{id}")
    public Result<Map<String, Object>> show(@ApiParam(name = "id", value = "医院id", required = true)
                                 @PathVariable String id) {
        return Result.ok(hospitalService.show(id));
    }

}
